package com.daiyang.lottery.dao.mapper;

import com.daiyang.lottery.dao.dataobject.PrizeDO;
import jakarta.validation.constraints.NotNull;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrizeMapper {
    /**
     * 插入奖品信息
     * @param prizeDO
     * @return
     */
    @Insert("insert into prize(description, image_url, name, price)"
            + " values(#{description}, #{imageUrl}, #{name}, #{price})")
    @Options(useGeneratedKeys = true ,keyProperty = "id", keyColumn = "id")
    int insert(PrizeDO prizeDO);

    /**
     * 查询奖品总数
     * @return
     */
    @Select("select count(1) from prize")
    int count();

    /**
     * 分页查询奖品信息
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> queryPrizesPage(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);



    @Select("<script>"+
            " select id from prize " +
            " where id in " +
            " <foreach  item='item'  collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach> " +
            "</script>")
    List<Long> selectExistByIds(@Param("items") List<Long> Ids);


    @Select({"<script>",
            " SELECT * FROM prize WHERE id IN",
            " <foreach item='id' collection='prizeIds' open='(' separator=',' close=')'>",
            " #{id}",
            " </foreach>",
            " </script>"})
    List<PrizeDO> selectByIdList(@Param("prizeIds") List<Long> prizeIds);
    @Select("<script>"+
            " select * from prize " +
            " where id in " +
            " <foreach  item='item'  collection='prizeIds' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach> " +
            "</script>")
    List<PrizeDO> batchSelectByIds(@Param("prizeIds") List<Long> prizeIds);


    @Select("select * from prize where id = #{prizeId}")
    PrizeDO selecrtById(@NotNull(message = "奖品id不能为空") Long prizeId);
}
